﻿$(function() {
	/**
	 * 设备开动情况
	 * */
    var dayline = echarts.init(document.getElementById('singlechart'));
    optionline = {
        tooltip : {
            trigger: 'axis',
            axisPointer: {
		        type: 'shadow'
		    }
        },
        backgroundColor:'#e0e0e0',
        grid: {
            top: '15%',
            left: '4%',
            right: '5%',
            bottom:'20%',
            containLabel: true
        },
        legend: {
        	top: '10',
	        data:['开动率','满载率']
	    },
        xAxis:  {
            type: 'category',
            boundaryGap: [1, 1],
            data: [],//['1','2','3','4','5','6'],
            splitLine:{
            	show:false
            }
        },
        yAxis: {
        	min:0,
        	max:100,
            type: 'value',
            name:'开动率',
            axisLabel:{
	    		 formatter: '{value}'
	    	 },
            splitLine:{
            	show:false
            }
        },
        dataZoom:{
	    	type:'slider',
	    	start:0,
	    	end:100,
//	    	labelFormatter: function (value) {
//	    	    return value; // 返回最终的label内容。
//	    	},
	    	bottom:20
	    },
        series: [{
             name:'开动率',
             type:'line',
             data:[]//[0.8,0.9,0.84,0.7,0.8,0.91],
         },{
             name:'满载率',
             type:'line',
             data:[]//[0.83,0.75,0.89,0.91,0.79,0.93],
         }]
    };
    dayline.setOption(optionline);
    
    var equId=0;
    var	startTime="";
    var	endTime="";
    /**
     * slider滑动事件
     * */
    $('#ss').slider({
    	range: true,
        onComplete:function(value){//滑块值改变时触发
//	       	time=moment(value).format('YYYY-MM-DD');
	       	startTime=moment(value[0]).format('YYYY-MM-DD');
	       	endTime=moment(value[1]).format('YYYY-MM-DD');
	       	getData();
       }
    });
    /**
     * 初始化
     * */
    
    var vm = new Vue({
	    el: '#itemData',
	    data:{item:[]}
	});
    var timess=[parseInt(moment().subtract(7, 'days').format("x")),parseInt(moment().format("x"))];
    $('#ss').slider('setValues',timess);
    var arr=$('#ss').slider('getValues');
    var time1=arr[0];
    var time2=arr[1];
    startTime=moment(time1).format("YYYY-MM-DD");
    endTime=moment(time2).format("YYYY-MM-DD");
    getData();
    function getData(){
    	$.post(basePath+"/energy/capasityData/complex.json",{"equMoldId":equId,startDate:startTime,endDate:endTime},function(res){
    		vm.$set('item',res);
    		if(res.success){
    			dayline.setOption({
			        xAxis: {
			            data: res.equNames
			        },
			        series: [{
			        	name:'开动率',
			            data: res.startRateLine
			        },{
			        	name:'满载率',
			            data: res.fullRateLine
			        }]
    			});
    		}else{
    			alert(res.msg);
    			dayline.setOption({
			        xAxis: {
			            data: []
			        },
			        series: [{
			        	name:'开动率',
			            data: []
			        },{
			        	name:'满载率',
			            data: []
			        }]
    			});
    		}	
    	});
    }

    
    /**
     * 自定义时间按钮的点击事件
     * */
	 $("#defineTime").click(function (){
		 var mePanel = $('#defineTimeWin');
	   	 mePanel.dialog('open');
	 });
	 /**
	  * 选择设备类型按钮的点击事件
	  */
	 $("#switchMoldbtn").click(function(){
		 var mePanel = $('#switchEquMold');
   		 mePanel.dialog('open');
   		$('#equipMold_data').datagrid({
	  		onDblClickRow: function(rowIndex, rowData){
	  			equId=rowData.id;
                getData();
	  		    mePanel.dialog('close');
	  		}
   		});
	 });
	 
	 $("#switchEquMoldOK").click(function(){
	    	var equWin=$("#switchEquMold");
	    	var row=$('#equipMold_data').datagrid('getSelected');
	    	equId=row.id;
//	    	var arr=$('#ss').slider('getValues');
//		    var time1=arr[0];
//		    var time2=arr[1];
//		    startTime=moment(time1).format("YYYY-MM-DD");
//		    endTime=moment(time2).format("YYYY-MM-DD");
		    getData();
	    	equWin.dialog('close');
	    });

    

    
});